﻿using Bottle.CommunityForum.IBLL;
using Bottle.CommunityForum.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bottle.CommunityForum.BLL
{
    public partial class NodesInfoService : BaseService<NodesInfo>,INodesInfoService
    {
        /// <summary>
        /// 节点多条件查询
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="queryNodesParam"></param>
        /// <param name="ordlambda"></param>
        /// <returns></returns>
        public IQueryable<NodesInfo> QueryWhereLoadPage<S>(Model.Param.NodesInfoParam queryNodesParam, System.Linq.Expressions.Expression<Func<NodesInfo, S>> ordlambda)
        {
            //查询所有的节点
            var Param = Db.NodesInfoDal.QueryEntitys(n => true);
            //获取节点的总数
            queryNodesParam.totle = Param.Count();
            //排序方式
            if (queryNodesParam.isOrder)
            {
                //正序
                Param = Param.OrderBy(ordlambda)
                    .Skip(queryNodesParam.pageSize * (queryNodesParam.pageIndex - 1))
                    .Take(queryNodesParam.pageSize)
                    .AsQueryable();
            }
            else
            {
                //倒序
                Param = Param.OrderByDescending(ordlambda)
                    .Skip(queryNodesParam.pageSize * (queryNodesParam.pageIndex - 1))
                    .Take(queryNodesParam.pageSize)
                    .AsQueryable();
            }

            return Param;
        }
    }
}
